package pc2brick;
import lejos.nxt.*;
import lejos.robotics.Colors.Color;


public class color {
	

	public static void main(String[] args) throws Exception 
	{
		ColorLightSensor cs = new ColorLightSensor(SensorPort.S2, 0);
		TouchSensor touch = new TouchSensor(SensorPort.S4);
		
		Motor.A.setSpeed(100);
		Motor.C.setSpeed(100);
		
		Motor.A.forward();
		Motor.C.forward();
		
		while(!touch.isPressed()) {
			int[] c = cs.getColor();
			String s = "r:"+c[0]+"\ng:"+c[1]+"\nb:"+c[2];
			String couleur = color.getColor(c);
			//couleur+=s;
			LCD.clear();
			LCD.drawString(couleur, 2,2);
			LCD.drawString(s, 5, 3);
			
			/*Color color = cs.readColor();
			
			LCD.clear();
			LCD.drawString(color.toString(), 2,2);*/
		}
		
		Motor.A.stop();
		Motor.C.stop();
		
	}
	private static String getColor(int[] c) {
		/*if((c[0]>75) && (c[1]>75) && (c[2]>75)) {return "white";}
		else if (c[0]>150 && (c[0] > c[1]) && (c[0] > c[2])) {return "red";}
		else if (c[1]>50 && (c[0] < c[1]) && (c[1] > c[2])) {return "green";}
		else if (c[2]>50 && (c[2] > c[0]) && (c[1] < c[2])) {return "blue";}
		else {return "black";}*/
	
		if(c[0]<100 && c[1]>100 && c[2]<100) {return "green";}
		else if (c[0]<100 && c[1]<100 && c[2]>100) {return "blue";}
		else if (c[0]>130 && c[1]<100 && c[2]<100) {return "red";}
		else if (c[0]<100 && c[1]<100 && c[2]<100) {return "black";}
		else {return "white";}
	}
	
}